package com.efast.cafe.portal.service.company.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.efast.cafe.framework.exception.ServiceException;
import com.efast.cafe.portal.bean.company.PortalCompanyUserBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.efast.cafe.framework.constant.CommonConstant;
import com.efast.cafe.framework.jdbc.JdbcDao;
import com.efast.cafe.framework.jdbc.persistence.Criteria;
import com.efast.cafe.framework.util.SpringWebUtils;
import com.efast.cafe.portal.dao.company.PortalCompanyOrgDao;
import com.efast.cafe.portal.dao.company.PortalCompanyPositionDao;
import com.efast.cafe.portal.dao.company.PortalCompanyUserDao;
import com.efast.cafe.portal.dao.company.PortalCompanyUserReporttoDao;
import com.efast.cafe.portal.entity.base.PortalBaseParameter;
import com.efast.cafe.portal.entity.company.PortalCompanyOrg;
import com.efast.cafe.portal.entity.company.PortalCompanyPosition;
import com.efast.cafe.portal.entity.company.PortalCompanyUser;
import com.efast.cafe.portal.entity.company.PortalCompanyUserOrg;
import com.efast.cafe.portal.entity.company.PortalCompanyUserReportto;
import com.efast.cafe.portal.entity.company.PortalCompanyUserReporttoTreeDto;
import com.efast.cafe.portal.remote.common.ParameterService;
import com.efast.cafe.portal.service.company.IPortalCompanyUserReporttoService;
import com.efast.cafe.util.StringUtil;

/******************************************************************************
 * @File name : PortalCompanyUserReporttoServiceImpl.java
 *
 * @Author : xl
 *
 * @Date : 2016-8-22
 *
 * @Copyright Notice: Copyright (c) 2016 Efast Serv. All Rights Reserved. This
 *            software is published under the terms of the Efast Software
 *            License version 1.0, a copy of which has been included with this
 *            distribution in the LICENSE.txt file.
 * 
 * 
 *            ------------------------------------------------------------------
 *            ---------- Date Who Version Comments 2016-8-22 下午3:18:25 xl 1.0
 *            Initial Version
 *****************************************************************************/
@Service
@Transactional
public class PortalCompanyUserReporttoServiceImpl implements IPortalCompanyUserReporttoService {

	@Qualifier("jdbcDao")
	@Autowired
	private JdbcDao jdbcDao;

	private PortalCompanyPositionDao portalCompanyPositionDao;

	private PortalCompanyUserDao portalCompanyUserDao;
	@Autowired
	private PortalCompanyOrgDao portalCompanyOrgDao;
	@Autowired
	private PortalCompanyUserReporttoDao portalCompanyUserReporttoDao;
	@Autowired
	private ParameterService parameterService;

	@Autowired
	public void setPortalCompanyUserDao(PortalCompanyUserDao portalCompanyUserDao) {
		this.portalCompanyUserDao = portalCompanyUserDao;
	}

	@Autowired
	public void setPortalCompanyPositionDao(PortalCompanyPositionDao portalCompanyPositionDao) {
		this.portalCompanyPositionDao = portalCompanyPositionDao;
	}

	/**
	 * {@inheritDoc} overridden:
	 * 
	 * @Date : 2016-8-22
	 * @see org.eae.eldf.portal.remote.company.PortalCompanyUserReporttoService#getTree()
	 **/
	@Override
	public List<PortalCompanyUserReporttoTreeDto> getCompanyTree() {
		// 获取参数组织机构中职位是否启用
		PortalBaseParameter paramValue = parameterService
				.api_getParameter(CommonConstant.ParameterKeys.COMPANY_POSITION_ENABLE, "Global");
		boolean isEnablePosition = true;
		if (null != paramValue) {
			isEnablePosition = Boolean.parseBoolean(paramValue.getParam_value());
		}
		List<PortalCompanyUserReporttoTreeDto> list = new ArrayList<PortalCompanyUserReporttoTreeDto>();

		Criteria userCriteria = Criteria.create(PortalCompanyUser.class).where("companyCode",
				new Object[] { SpringWebUtils.getRequestCompany() });
		List<PortalCompanyUser> listUser = jdbcDao.queryList(userCriteria);

		Map<String, PortalCompanyUser> mapUser = new HashMap<String, PortalCompanyUser>();
		for (PortalCompanyUser portalCompanyUser : listUser) {
			mapUser.put(portalCompanyUser.getUsername(), portalCompanyUser);
		}

		Criteria orgCriteria = Criteria.create(PortalCompanyOrg.class).where(PortalCompanyOrg.companyCode,
				new Object[] { SpringWebUtils.getRequestCompany() });
		List<PortalCompanyOrg> listOrg = jdbcDao.queryList(orgCriteria);
		for (PortalCompanyOrg portalCompanyOrg : listOrg) {
			PortalCompanyUserReporttoTreeDto dto = new PortalCompanyUserReporttoTreeDto();
			dto.setId("org_" + portalCompanyOrg.getPortal_company_org_id());
			dto.setName(portalCompanyOrg.getOrg_name());
			dto.setParentId("org_" + portalCompanyOrg.getParent_id());
			dto.setType("org");
			dto.setIconSkin("org");
			dto.setIsHidden(false);
			list.add(dto);
		}
		if (isEnablePosition) {
			Criteria positionCriteria = Criteria.create(PortalCompanyPosition.class).where(PortalCompanyOrg.companyCode,
					new Object[] { SpringWebUtils.getRequestCompany() });
			List<PortalCompanyPosition> listPosition = jdbcDao.queryList(positionCriteria);
			for (PortalCompanyPosition portalCompanyPosition : listPosition) {
				PortalCompanyUserReporttoTreeDto dto = new PortalCompanyUserReporttoTreeDto();
				dto.setId("position_" + portalCompanyPosition.getPortal_company_position_id());
				dto.setName(portalCompanyPosition.getPosition_name());
				dto.setParentId("org_" + portalCompanyPosition.getPortal_company_org_id());
				dto.setType("position");
				dto.setIsHidden(false);
				dto.setIconSkin("position");
				list.add(dto);
			}
		}

		/*
		 * Criteria
		 * userorgCriteria=Criteria.create(PortalCompanyUserOrg.class).where(
		 * PortalCompanyUserOrg.companyCode, new
		 * Object[]{SpringWebUtils.getRequestCompany()});
		 * List<PortalCompanyUserOrg>
		 * listUserOrg=jdbcDao.queryList(userorgCriteria);
		 */
		List<PortalCompanyUserOrg> listUserOrg = portalCompanyUserReporttoDao.queryUserOrgList();
		for (PortalCompanyUserOrg portalCompanyUserOrg : listUserOrg) {
			PortalCompanyUserReporttoTreeDto user = new PortalCompanyUserReporttoTreeDto();
			user.setId("user_" + portalCompanyUserOrg.getUsername() + "_"
					+ portalCompanyUserOrg.getPortal_company_user_org_id());
			user.setName(portalCompanyUserOrg.getUsername());
			if (isEnablePosition) {// 如果启用了职位则创建职位与用户的关系
				user.setParentId("position_" + portalCompanyUserOrg.getPortal_company_position_id());
			} else {// 如果没有启用职位则创建组织与用户的关系
				user.setParentId("org_" + portalCompanyUserOrg.getPortal_company_org_id());
			}
			user.setType("user");
			user.setIsHidden(false);
			user.setIconSkin("user");
			list.add(user);
		}

		return list;
	}

	/**
	 * {@inheritDoc} overridden:
	 * 
	 * @Date : 2016-8-22
	 * @see org.eae.eldf.portal.remote.company.PortalCompanyUserReporttoService#getTree()
	 **/
	@Override
	public List<PortalCompanyUserReporttoTreeDto> getCompanyIdentityTree() {
		String username = SpringWebUtils.getRequestUser();
		String companyCode = SpringWebUtils.getRequestCompany();
		PortalCompanyPosition defaultPosition = portalCompanyUserReporttoDao.queryUserOrgPosition(username,
				companyCode);
		List<PortalCompanyUserReporttoTreeDto> list = new ArrayList<PortalCompanyUserReporttoTreeDto>();

		List<PortalCompanyUserOrg> listUserOrg = portalCompanyUserReporttoDao.queryUserList(username, companyCode);
		// 去除重复的
		Map<String, PortalCompanyUserReporttoTreeDto> map = new HashMap<>();
		if (listUserOrg != null && listUserOrg.size() > 0) {
			List<PortalCompanyPosition> listPosition = portalCompanyUserReporttoDao.queryPositionList(companyCode,
					listUserOrg);
			for (PortalCompanyPosition portalCompanyPosition : listPosition) {
				PortalCompanyUserReporttoTreeDto dto = new PortalCompanyUserReporttoTreeDto();
				dto.setId("position_" + portalCompanyPosition.getPortal_company_position_id());
				dto.setName(portalCompanyPosition.getPosition_name());
				dto.setParentId("org_" + portalCompanyPosition.getPortal_company_org_id());
				dto.setType("position");
				dto.setIsHidden(false);
				dto.setIconSkin("position");
				if (defaultPosition != null && portalCompanyPosition.getPortal_company_position_id().toString()
						.equals(defaultPosition.getPortal_company_position_id().toString())) {
					dto.setIsDefault(true);
				}
				list.add(dto);
			}
			List<PortalCompanyOrg> listOrg = portalCompanyUserReporttoDao.queryOrgList(companyCode);
			/*
			 * for (PortalCompanyOrg portalCompanyOrg : listOrg) {
			 * PortalCompanyUserReporttoTreeDto dto = new
			 * PortalCompanyUserReporttoTreeDto();
			 * dto.setId("org_"+portalCompanyOrg.getPortal_company_org_id());
			 * dto.setName(portalCompanyOrg.getOrg_name());
			 * dto.setParentId("org_"+portalCompanyOrg.getParent_id());
			 * dto.setType("org"); dto.setIconSkin("org");
			 * dto.setIsHidden(false); list.add(dto); }
			 */
			List<PortalCompanyOrg> newListOrg = new ArrayList<>();
			List<PortalCompanyOrg> tempList = new ArrayList<>();
			// 获取需要的上级组织
			for (int i = 0; i < listOrg.size(); i++) {
				for (int j = 0; j < listPosition.size(); j++) {
					if (listPosition.get(j).getPortal_company_org_id()
							.equals(listOrg.get(i).getPortal_company_org_id())) {
						tempList.add(listOrg.get(i));
						newListOrg.add(listOrg.get(i));
					}
				}
			}
			newListOrg = getOrgInfo(listOrg, newListOrg, tempList);

			for (PortalCompanyOrg portalCompanyOrg : newListOrg) {
				PortalCompanyUserReporttoTreeDto dto = new PortalCompanyUserReporttoTreeDto();
				dto.setId("org_" + portalCompanyOrg.getPortal_company_org_id());
				dto.setName(portalCompanyOrg.getOrg_name());
				dto.setParentId("org_" + portalCompanyOrg.getParent_id());
				dto.setType("org");
				dto.setIconSkin("org");
				dto.setIsHidden(false);
				map.put("org_" + portalCompanyOrg.getPortal_company_org_id(), dto);
				// list.add(dto);
			}
		}
		for (PortalCompanyUserOrg portalCompanyUserOrg : listUserOrg) {
			PortalCompanyUserReporttoTreeDto user = new PortalCompanyUserReporttoTreeDto();
			user.setId("user_" + portalCompanyUserOrg.getUsername() + "_"
					+ portalCompanyUserOrg.getPortal_company_user_org_id());
			user.setName(portalCompanyUserOrg.getUsername());
			user.setParentId("position_" + portalCompanyUserOrg.getPortal_company_position_id());
			user.setType("user");
			user.setIsHidden(false);
			user.setIconSkin("user");
			list.add(user);
		}
		Set<String> keys = map.keySet(); // 此行可省略，直接将map.keySet()写在for-each循环的条件中
		for (String key : keys) {
			list.add(map.get(key));
		}
		return list;
	}

	public static List<PortalCompanyOrg> getOrgInfo(List<PortalCompanyOrg> listOrg, List<PortalCompanyOrg> newListOrg,
			List<PortalCompanyOrg> tempList) {
		List<PortalCompanyOrg> temp = new ArrayList<>();
		for (int i = 0; i < listOrg.size(); i++) {
			for (int j = 0; j < tempList.size(); j++) {
				if (listOrg.get(i).getPortal_company_org_id().equals(tempList.get(j).getParent_id())) {
					newListOrg.add(listOrg.get(i));
					temp.add(listOrg.get(i));
				}
			}
		}
		if (temp.size() > 0) {
			return getOrgInfo(listOrg, newListOrg, temp);
		}
		return newListOrg;

	}

	/**
	 * {@inheritDoc} overridden:
	 * 
	 * @Date : 2016-8-24
	 * @see org.eae.eldf.portal.remote.company.PortalCompanyUserReporttoService#getUserMultiple()
	 **/
	@Override
	public Map<String, List<PortalCompanyUser>> getUserMultiple(String username, String[] names, Long positionId, Long orgId) {
		Map<String, List<PortalCompanyUser>> data = new HashMap<String, List<PortalCompanyUser>>();
		Criteria orgCriteria = null ;
		if(positionId!=null){
			orgCriteria = Criteria.create(PortalCompanyUserOrg.class)
					.where(PortalCompanyUserOrg.userName, new Object[] { username })
					.and(PortalCompanyUserOrg.portalCompanyPositionId, new Object[] { positionId });
		}else if(orgId !=null){
			orgCriteria = Criteria.create(PortalCompanyUserOrg.class)
					.where(PortalCompanyUserOrg.userName, new Object[] { username }) ;
			if(orgId != 0 ){
				orgCriteria.and(PortalCompanyUserOrg.portalCompanyOrgId, new Object[] { orgId });
			}
		}



		List<PortalCompanyUserOrg> lisstOrg = jdbcDao.queryList(orgCriteria);

		List<PortalCompanyUser> userHasSelectList = new ArrayList<PortalCompanyUser>();
		List<Long> orgIdList = new ArrayList<>();
		if (lisstOrg.size() > 0) {
			userHasSelectList = portalCompanyUserDao.queryByOrgAndUser(lisstOrg.get(0).getPortal_company_user_org_id(),
					SpringWebUtils.getRequestCompany());
			// 根据组织id,查询所有上级组织id
			List<PortalCompanyOrg> listpoPortalCompanyOrgList = portalCompanyOrgDao
					.queryPortalCompanyOrgList(SpringWebUtils.getRequestCompany());
			orgId = lisstOrg.get(0).getPortal_company_org_id();
			orgIdList.add(orgId);
			boolean flag = true;
			if (flag) {
				for (int i = 0; i < listpoPortalCompanyOrgList.size(); i++) {
					if (orgId.equals(listpoPortalCompanyOrgList.get(i).getPortal_company_org_id())) {
						orgId = listpoPortalCompanyOrgList.get(i).getParent_id();
						if (orgId != 0) {
							orgIdList.add(orgId);
						} else {
							flag = false;
							break;
						}
						break;
					}
				}
			}
		}
		// 查看同级及上级的用户
		List<String> nameList = new ArrayList<>();
		nameList = portalCompanyUserDao.queryNamesListByOrgId(orgIdList, username, SpringWebUtils.getRequestCompany());
		if (!(names != null && names.length > 0)) {
			names = nameList.toArray(new String[nameList.size()]);
		}
		List<PortalCompanyUser> userNotHasSelectList = new ArrayList<>();
		if (names != null && names.length > 0) {
			userNotHasSelectList = portalCompanyUserDao.queryByNotReporttoUserName(names, userHasSelectList,
					SpringWebUtils.getRequestCompany());

		}
		data.put("userHasSelectList", userHasSelectList);
		data.put("userNotHasSelectList", userNotHasSelectList);
		return data;
	}

	/**
	 * {@inheritDoc} overridden:
	 * 
	 * @Date : 2016-8-24
	 * @see org.eae.eldf.portal.remote.company.PortalCompanyUserReporttoService#getPositionMultiple()
	 **/
	@Override
	public Map<String, List<PortalCompanyUser>> getPositionMultiple(String[] names) {
		Map<String, List<PortalCompanyUser>> data = new HashMap<String, List<PortalCompanyUser>>();
		List<PortalCompanyUser> userHasSelectList = new ArrayList<>();
		if (names != null && names.length > 0) {
			userHasSelectList = portalCompanyUserDao.queryByListUser(names, SpringWebUtils.getRequestCompany());
		}

		List<PortalCompanyUser> userNotHasSelectList = portalCompanyUserDao
				.queryByNotPositionUserName(userHasSelectList, SpringWebUtils.getRequestCompany());
		data.put("userHasSelectList", userHasSelectList);
		data.put("userNotHasSelectList", userNotHasSelectList);
		return data;
	}

	/**
	 * {@inheritDoc} overridden:
	 * 
	 * @Date : 2016-8-25
	 * @see org.eae.eldf.portal.remote.company.PortalCompanyUserReporttoService#reporttoUser(java.lang.String,
	 *      java.lang.String[])
	 **/
	@Override
	public String reporttoUser(String username, Long positionId, Long orgId, String[] names) {
		Criteria orgCriteria = null ;
		if(positionId!=null) {
			orgCriteria = Criteria.create(PortalCompanyUserOrg.class)
					.where(PortalCompanyUserOrg.userName, new Object[] { username })
					.and(PortalCompanyUserOrg.portalCompanyPositionId, new Object[] { positionId });
		}else if(orgId!=null){
			orgCriteria = Criteria.create(PortalCompanyUserOrg.class)
					.where(PortalCompanyUserOrg.userName, new Object[] { username })
					.and(PortalCompanyUserOrg.portalCompanyOrgId, new Object[] { orgId });
		}
		List<PortalCompanyUserOrg> lisstOrg = jdbcDao.queryList(orgCriteria);
		if (lisstOrg.size() > 0) {
			PortalCompanyUserOrg portalCompanyUserOrg = lisstOrg.get(0);
			Criteria delReporttoUser = Criteria.create(PortalCompanyUserReportto.class).where(
					PortalCompanyUserReportto.portalCompanyUserOrgId,
					new Object[] { portalCompanyUserOrg.getPortal_company_user_org_id() });
			jdbcDao.delete(delReporttoUser);
			for (String name : names) {
				Criteria reporttoUser = Criteria.create(PortalCompanyUserReportto.class)
						.set(PortalCompanyUserReportto.portalCompanyUserOrgId,
								portalCompanyUserOrg.getPortal_company_user_org_id())
						.set(PortalCompanyUserReportto.companyCode, SpringWebUtils.getRequestCompany())
						.set(PortalCompanyUserReportto.reportTo, name);
				jdbcDao.insert(reporttoUser);
			}

		}

		return "success";
	}

	/**
	 * {@inheritDoc} overridden:
	 * 
	 * @Date : 2016-8-25
	 * @see org.eae.eldf.portal.remote.company.PortalCompanyUserReporttoService#reporttoPosition(java.lang.String,
	 *      java.lang.String[])
	 **/
	@Override
	public String reporttoPosition(Long positionId, Long orgId, String[] names) {
		// 获取参数组织机构中职位是否启用
		PortalBaseParameter paramValue = parameterService
				.api_getParameter(CommonConstant.ParameterKeys.COMPANY_POSITION_ENABLE, "Global");
		boolean isEnablePosition = true;
		if (null != paramValue) {
			isEnablePosition = Boolean.parseBoolean(paramValue.getParam_value());
		}
		if (isEnablePosition) {// 启用职位
			saveReporttoPosition(positionId,orgId,names);

		} else {// 不启用职位
			saveReporttoPosition(positionId,orgId,names);
		}
		return "success";
	}


	public void saveReporttoPosition(Long positionId,Long orgId,String[] names ){
		if(positionId != null){
			Criteria criteria = Criteria.create(PortalCompanyUserOrg.class)
					.where(PortalCompanyUserOrg.portalCompanyPositionId, new Object[] { positionId });
			jdbcDao.delete(criteria);
			PortalCompanyPosition portalCompanyPosition = portalCompanyPositionDao.queryPositionById(positionId);
			for (String name : names) {
				Criteria userOrg = Criteria.create(PortalCompanyUserOrg.class)
						.set(PortalCompanyUserOrg.companyCode, SpringWebUtils.getRequestCompany())
						.set(PortalCompanyUserOrg.userName, name)
						.set(PortalCompanyUserOrg.portalCompanyPositionId, positionId)
						.set(PortalCompanyUserOrg.portalCompanyOrgId, portalCompanyPosition.getPortal_company_org_id());
				jdbcDao.insert(userOrg);
			}
		}else if(orgId != null){
			Criteria criteria = Criteria.create(PortalCompanyUserOrg.class)
					.where(PortalCompanyUserOrg.portalCompanyOrgId, new Object[] { orgId });
			jdbcDao.delete(criteria);
			for (String name : names) {
				Criteria userOrg = Criteria.create(PortalCompanyUserOrg.class)
						.set(PortalCompanyUserOrg.companyCode, SpringWebUtils.getRequestCompany())
						.set(PortalCompanyUserOrg.userName, name).set(PortalCompanyUserOrg.portalCompanyPositionId, 0)
						.set(PortalCompanyUserOrg.portalCompanyOrgId, orgId);
				jdbcDao.insert(userOrg);
			}
		}
	}
	// 选择或者查看默认职位
	@Override
	public PortalCompanyUserReporttoTreeDto choiceDefaultPosition(PortalCompanyUserReporttoTreeDto bean) {

		String username = SpringWebUtils.getRequestUser();
		String companyCode = SpringWebUtils.getRequestCompany();

		if (StringUtil.isEmpty(bean.getId())) {
			// 查看默认职位
			PortalCompanyPosition portalCompanyPosition = portalCompanyUserReporttoDao.queryUserOrgPosition(username,
					companyCode);
			if (portalCompanyPosition == null) {
				return null;
			}
			PortalCompanyUserReporttoTreeDto dto = new PortalCompanyUserReporttoTreeDto();
			dto.setId("position_" + portalCompanyPosition.getPortal_company_position_id());
			dto.setName(portalCompanyPosition.getPosition_name());
			dto.setParentId("org_" + portalCompanyPosition.getPortal_company_org_id());
			dto.setType("position");
			dto.setIsHidden(true);
			dto.setIconSkin("position");
			return dto;
		} else {
			// 保存默认职位
			portalCompanyUserReporttoDao.updateUserOrgPosition(username, companyCode, 0);
			Integer id = Integer.parseInt(bean.getId().split("_")[1]);
			portalCompanyUserReporttoDao.updateUserOrgPositionById(1, id);
		}
		return null;
	}

	@Override
	public void addUserByOrg(Long positionId, Long orgId, List<String> usernames) {
		String companyCode=SpringWebUtils.getRequestCompany();
		if(positionId != null){
			//查询该职位下的人员
			List<String> oldUsername=portalCompanyUserReporttoDao.queryUsernameByPositionId(companyCode,positionId);
			usernames.removeAll(oldUsername);
			if(usernames.size()==0){
				throw new ServiceException("用户已存在");
			}
			//获取该职位的组织
			PortalCompanyPosition portalCompanyPosition = portalCompanyPositionDao.queryPositionById(positionId);
			portalCompanyUserReporttoDao.addUsernameByPositionIdOrOrgId(companyCode,positionId,portalCompanyPosition.getPortal_company_org_id(),usernames);
		}else if(orgId != null){
			//查询该职位下的人员
			List<String> oldUsername=portalCompanyUserReporttoDao.queryUsernameByOrgId(companyCode,orgId);
			usernames.removeAll(oldUsername);
			if(usernames.size()==0){
				throw new ServiceException("用户已存在");
			}
			//获取该职位的组织
			portalCompanyUserReporttoDao.addUsernameByPositionIdOrOrgId(companyCode,0L,orgId,usernames);

		}
	}

	@Override
	public void deleteUserByOrg(Long positionId, Long orgId, List<String> usernames) {
		String companyCode=SpringWebUtils.getRequestCompany();
		if(positionId != null){
			//获取该职位的组织
			PortalCompanyPosition portalCompanyPosition = portalCompanyPositionDao.queryPositionById(positionId);
			portalCompanyUserReporttoDao.deleteUsernameByPositionIdOrOrgId(companyCode,positionId,portalCompanyPosition.getPortal_company_org_id(),usernames);
		}else if(orgId != null){
			//List<String> oldUsername=portalCompanyUserReporttoDao.queryUsernameByOrgId(companyCode,orgId);

			//portalCompanyUserReporttoDao.deleteUsernameByPositionIdOrOrgId(companyCode,0L,orgId,usernames);

			List<PortalCompanyUserBean> listOrgUser=portalCompanyUserDao.queryUserInfoByOrgId(companyCode,orgId);
			//批量删除用户
            if(listOrgUser!=null&&listOrgUser.size()>0){
            	for(int i=0;i<listOrgUser.size();i++){
            		if(usernames.contains(listOrgUser.get(i).getUsername())){
            			//删除组织上的人
						portalCompanyUserReporttoDao.deleteUsernameByOrgId(companyCode,listOrgUser.get(i).getPortalCompanyOrgId(),listOrgUser.get(i).getUsername());
					}
				}
			}
			/*usernames.removeAll(oldUsername);
			if(usernames.size()>0){
				s=usernames.toString()+"删除不成功";
			}*/

		}
	}

}
